package cn.dai.wechat.pojo;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;

/**
 * @author daijiyong
 */
@Data
public class WechatTokenDto {
    private Integer errCode;
    private String errMsg;
    private String token;
    private Long expires;

    public static WechatTokenDto builder(JSONObject json) {
        WechatTokenDto tokenDto = new WechatTokenDto();
        tokenDto.setToken(json.getString("access_token"));
        tokenDto.setErrMsg(json.getString("errmsg"));
        tokenDto.setErrCode(json.getInteger("errcode"));
        tokenDto.setExpires(json.getLong("expires_in") - 10000);
        return tokenDto;
    }
}
